<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function fn(a, b) {
            console.log(this);
            console.log(a + b);
            return 'hello';
        }

        Function.prototype.myBind = function (o) {
            // 存储this
            var _self = this;
            // 存储argumnets,并将argumnets转换成数组
            var arg = Array.from(arguments);
            return function () {
                // 返回一个改变了this指向函数
                // 用apply改变this指向
                // 返回函数的返回值
                return _self.apply(o, arg.slice(1));
            }
        }

        var result = fn.myBind({ name: '张珊' }, 1, 2);
        // console.log(result);
        console.log(result);
    </script>
</body>

</html>